Ext.define('appfe.stockor.statist.buyinpoint.form.BuyinPointLogGridController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.stockor.statist.buyinpoint.form.BuyinPointLogGrid',

    onRender: function () {

    },
    onBoxReady: function () {
        var urlParamters = Ext.Object.fromQueryString(window.location.search)

        var myviewmodel = this.getView().getViewModel();
        if (!urlParamters.id) {
            //console.debug('urlParamters.id is blank');
            return;
        }

		myviewmodel.set('buyinPoint.id', urlParamters.id);
		myviewmodel.set('buyinPoint.slimsymbol', urlParamters.slimsymbol);
		myviewmodel.set('buyinPoint.stkname', urlParamters.stkname);
		myviewmodel.set('buyinPoint.grade', urlParamters.grade);
		//设置加载窗口的数据源
		myviewmodel.getStore('buyinPointLogStore').load({
			params: { parentid: myviewmodel.get('buyinPoint.id') }
		});

        // new Ext.util.DelayedTask(function () {//延迟500ms, 不然数据结构还没构建完, 拿不到结果
        //     me.getView().store.load({
        //         params: { parentid: pid },
        //         callback: function (records, operation, success) { }
        //     });
        // }).delay(1000);
    },

    viewCellProfitAmountRender: function (value, metaData, record, rowIndex, colIndex, store, view) {
        if (value > 0) {
            metaData.tdAttr = 'bgcolor="red"';
            metaData.tdStyle = 'color:white';
        } else if (value < 0) {
            metaData.tdAttr = 'bgcolor="green"';
            metaData.tdStyle = 'color:white';
        }
        return Ext.util.Format.number(value, '￥0.00');
    },
    viewCellProfitRatioRender: function (value, metaData, record, rowIndex, colIndex, store, view) {

        if (value > 0) {
            metaData.tdAttr = 'bgcolor="red"';
            metaData.tdStyle = 'color:white';
        } else if (value < 0) {
            metaData.tdAttr = 'bgcolor="green"';
            metaData.tdStyle = 'color:white';
        }
        return Ext.util.Format.number(value * 100, '0.00%'); /*利润率*/
    },
    viewCellBooleanRender: function (value, metaData, record, rowIndex, colIndex, store, view) {
        if (value == true) {
            metaData.tdAttr = 'bgcolor="#00A800"';
            metaData.tdStyle = 'color:white';
            return '是';
        } else {
            metaData.tdAttr = 'bgcolor="LightGrey"';
            return '否';
        }
    },
    viewCellPlainTextRender: function (value) {/** grid cell 将html特殊字符替换 */
        return Ext.util.Format.htmlEncode(value);
    },
    viewCellStatusRender: function (value, metaData, record, rowIndex, colIndex, store, view) { /**	渲染cell */
        var rtntxt;
        if (value === 'NEW') {
            metaData.tdAttr = 'bgcolor="#00A800" data-qtip="新建"';
            metaData.tdStyle = 'color:white';
            rtntxt = 'NEW';
        } else if (value === 'OPEN') {
            metaData.tdAttr = 'bgcolor="#FF920D" data-qtip="有效"';
            metaData.tdStyle = 'color:white';
            rtntxt = 'OPEN';
        } else if (value === 'CLOSE') {
            metaData.tdAttr = 'bgcolor="LightGrey" data-qtip="关闭"';
            rtntxt = 'CLOSE';
        } else {
            metaData.tdAttr = 'bgcolor="red" data-qtip="未知"';
            metaData.tdStyle = 'color:white';
            rtntxt = 'N/A';
        }
        return rtntxt;
    }
});